﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Microsoft.Forums.ForumsClient
{
    /// <summary>
    /// Interaction logic for VistaThrobber.xaml
    /// </summary>
    public partial class WaitThrobber : UserControl
    {
        /// <summary>
        ///  DependencyProperty for Throb
        /// </summary>
        public static readonly DependencyProperty ThrobProperty =
           DependencyProperty.Register("Throb", typeof(bool), typeof(WaitThrobber), new UIPropertyMetadata(false));

        /// <summary>
        ///  DependencyProperty for Radius
        /// </summary>
        public static readonly DependencyProperty RadiusProperty =
            DependencyProperty.Register("Radius", typeof(int), typeof(WaitThrobber), new UIPropertyMetadata(16));

        public WaitThrobber()
        {
            InitializeComponent();
        }

        /// <summary>
        ///  Get or Set Throb property to true or false. This starts or stops the animation.
        /// </summary>
        public bool Throb
        {
            get
            {
                return (bool)GetValue(ThrobProperty);
            }
            set
            {
                SetValue(ThrobProperty, value);
            }

        }

        /// <summary>
        ///  Get / Set Radius of the Throbber circle
        /// </summary>
        public int Radius
        {
            get
            {
                return (int)GetValue(RadiusProperty);
            }
            set
            {
                SetValue(RadiusProperty, value);
            }

        }

        /// <summary>
        ///  Recalculate the Center of the circle and update the RotateTransform's CenterX and CenterY
        ///  This gets invoked whenever the Width / Height gets modified on the user control
        /// </summary>
        /// <param name="sizeInfo">Size Changed Info parameter</param>
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);

            RotateTransform rotateTransform = Template.FindName("RotateTransformElement", this) as RotateTransform;

            rotateTransform.CenterX = Radius / 2;
            rotateTransform.CenterY = Radius / 2;
        }
        
    }
}
